/*
 * Copyright (c) 2014 - 2016. Company.Domain Co.Ltd. All rights reserved.
 */

package cn.com.dhc.danlu.activity.category;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Bundle;
import android.renderscript.Int2;
import android.text.TextUtils;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.Gravity;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.WindowManager.LayoutParams;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;

import cn.com.dhc.danlu.R;
import cn.com.dhc.danlu.activity.BaseActivity;
import cn.com.dhc.danlu.dlware.OperatorUtils;
import cn.com.dhc.danlu.dlware.net.GeneralBusinessObserver;
import cn.com.dhc.danlu.util.ACache;
import cn.com.dhc.danlu.util.CommonConst;
import cn.com.dhc.danlu.util.CommonUtils;
import cn.com.dhc.danlu.util.CommonUtils.CachingArrayList;
import cn.com.dhc.danlu.util.SerializeCache;
import cn.com.dhc.danlu.util.ToastUtil;
import cn.com.hd.mall.web.common.ThreeTuple;
import cn.com.hd.mall.web.common.Tuple;
import cn.com.hd.mall.web.webservices.entity.request.merch.MerchCategoryListRequest;
import cn.com.hd.mall.web.webservices.entity.request.merch.MerchListRequest;
import cn.com.hd.mall.web.webservices.entity.response.merch.MerchCategoryListResponse;
import cn.com.hd.mall.web.webservices.entity.response.merch.MerchCategoryListResponse.BeerCategoryItem;
import cn.com.hd.mall.web.webservices.entity.response.merch.MerchCategoryListResponse.DailyUsedCategoryItem;
import cn.com.hd.mall.web.webservices.entity.response.merch.MerchCategoryListResponse.DrinksCategoryItem;
import cn.com.hd.mall.web.webservices.entity.response.merch.MerchCategoryListResponse.ElectricCategoryItem;
import cn.com.hd.mall.web.webservices.entity.response.merch.MerchCategoryListResponse.ForeignWineCategoryItem;
import cn.com.hd.mall.web.webservices.entity.response.merch.MerchCategoryListResponse.GrainCategoryItem;
import cn.com.hd.mall.web.webservices.entity.response.merch.MerchCategoryListResponse.HardwareCategoryItem;
import cn.com.hd.mall.web.webservices.entity.response.merch.MerchCategoryListResponse.NonStapleCategoryItem;
import cn.com.hd.mall.web.webservices.entity.response.merch.MerchCategoryListResponse.OthersCategoryItem;
import cn.com.hd.mall.web.webservices.entity.response.merch.MerchCategoryListResponse.SpiritCategoryItem;
import cn.com.hd.mall.web.webservices.entity.response.merch.MerchCategoryListResponse.TeaCategoryItem;
import cn.com.hd.mall.web.webservices.entity.response.merch.MerchCategoryListResponse.WineCategoryItem;

import static cn.com.dhc.danlu.dlware.global.DanluApplication.agent;
import static cn.com.dhc.danlu.util.CommonConst.IntentKey.BEER_CLASSIFY;
import static cn.com.dhc.danlu.util.CommonConst.IntentKey.BEER_COUNTRY;
import static cn.com.dhc.danlu.util.CommonConst.IntentKey.FOREIGN_CLASSIFY;
import static cn.com.dhc.danlu.util.CommonConst.IntentKey.FOREIGN_COUNTRY;

/**
 * author: MuWei
 * author: 刘立琦(<a href="mailto:liuliqi@danlu.com">liuliqi@danlu.com</a>)<br/>
 * version: 1.0.0<br/>
 * since: 2016-12-19 15:04<br/>
 *
 * <p>
 * 商品筛选画面
 * </p>
 */
public class CategoryFilterActivity extends BaseActivity {
    /**
     * 茶种
     */
    private static final String TEA_SORT = "茶种";
    /**
     * 茶类
     */
    private static final String TEA_SEED = "茶类";
    /**
     * 请求参数类
     */
    MerchListRequest goodsform = new MerchListRequest();
    String secondClassifyCode = "";
    /**
     * 取消按钮
     */
    private LinearLayout llytCancel;
    /**
     * 确定按钮
     */
    private LinearLayout llytOk;
    private LinearLayout llytPrice;
    /**
     * 选择品牌
     */
    private LinearLayout llytBrand;
    /**
     * 茶种
     */
    private LinearLayout llytTeaSort;
    /**
     * 茶类
     */
    private LinearLayout llytTeaSeed;
    /**
     * 香型
     */
    private LinearLayout llytOdorType;
    /**
     * 产地
     */
    private LinearLayout llytRwPlace;
    /**
     * 洋酒分类
     */
    private LinearLayout llytFwClassify;
    /**
     * 洋酒国家
     */
    private LinearLayout llytFwCountry;
    /**
     * 啤酒分类,饮料、粮油、副食、日化用品、五金、家电、其它 借用
     */
    private LinearLayout llytBClassify;
    /**
     * 啤酒国家
     */
    private LinearLayout llytBCountry;
    /**
     * 选择品牌
     */
    private TextView txtBrandName;
    /**
     * 选择价格
     */
    private TextView txtPrice;
    /**
     * 茶类
     */
    private TextView txtTeaSead;
    /**
     * 茶种
     */
    private TextView txtTeaSort;
    /**
     * 香型
     */
    private TextView txtOdorType;
    /**
     * 产地
     */
    private TextView txtRwPlace;
    /**
     * 洋酒颜色
     */
    private TextView txtFwClassify;
    /**
     * 洋酒国家
     */
    private TextView txtFwCountry;
    /**
     * 啤酒分类  饮料、粮油、副食、日化用品、五金、家电、其它 借用
     */
    private TextView txtClassify;
    /**
     * 啤酒国家
     */
    private TextView txtBCountry;
    /**
     * 选择品牌
     */
    private View lineBrand;
    /**
     * 茶类
     */
    private View lineTeaSead;
    /**
     * 茶种
     */
    private View lineTeaSort;
    /**
     * 香型
     */
    private View lineOdorType;
    /**
     * 产地
     */
    private View lineRwPlace;
    /**
     * 洋酒分类
     */
    private View lineFwClassify;
    /**
     * 洋酒国家
     */
    private View lineFwCountry;
    /**
     * 啤酒分类
     */
    private View lineClassify;
    /**
     * 啤酒国家
     */
    private View lineBCountry;
    /**
     * 意图对象
     */
    private Intent brandIntent;
    /**
     * 品牌码
     */
    private String brand = null;
    /**
     * 请求类参数
     */
    private List<String> propertyId = new ArrayList<>();
    /**
     * 茶请求类
     */
    private MerchCategoryListRequest brandListRequest = new MerchCategoryListRequest();

    /**
     * 类目code
     */
    private String code = "";
    /**
     * 白酒列表
     */
    private SpiritCategoryItem wineItem;
    /**
     * 葡萄酒列表
     */
    private WineCategoryItem redWineItem;
    /**
     * 茶列表
     */
    private ArrayList<TeaCategoryItem> teaItem;
    /**
     * 洋酒列表
     */
    private ForeignWineCategoryItem foreignItem;
    /**
     * 饮料列表
     */
    private DrinksCategoryItem drinksItem;
    /**
     * 饮料品牌列表
     */
    private DrinksCategoryItem drinksBrand;
    /**
     * 粮油列表
     */
    private GrainCategoryItem grainItem;
    /**
     * 粮油品牌列表
     */
    private GrainCategoryItem grainBrand;
    /**
     * 日化用品列表
     */
    private DailyUsedCategoryItem dailyUsedItem;
    /**
     * 日化用品品牌列表
     */
    private DailyUsedCategoryItem dailyUsedBrand;
    /**
     * 五金列表
     */
    private HardwareCategoryItem hardwareItem;
    /**
     * 五金品牌列表
     */
    private HardwareCategoryItem hardwareBrand;
    /**
     * 家电列表
     */
    private ElectricCategoryItem electricItem;
    /**
     * 家电品牌列表
     */
    private ElectricCategoryItem electricBrand;
    /**
     * 副食列表
     */
    private NonStapleCategoryItem nonStapleItem;
    /**
     * 副食品牌列表
     */
    private NonStapleCategoryItem nonStapleBrand;
    /**
     * 啤酒列表
     */
    private BeerCategoryItem beerItem;
    /**
     * 其他列表
     */
    private OthersCategoryItem othersItem;
    /**
     * 获取品牌缓存数据
     */
    private Tuple<String, String> tupleBrand;
    /**
     * 获取类目缓存数据
     */
    private Tuple<String, String> tupleCategory;
    /**
     * 获取属性缓存数据
     */
    private CachingArrayList tupleProperty;
    /**
     * 选择的一级商品分类
     */
    private String tab;
    /**
     * 价格tuple
     */
    private String tuplePrice;
    /**
     * 上一次选择的茶类
     */
    private String lastTea;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //        getDelegate().setContentView(R.layout.layout_category_filter, R.layout_category_filter.class);
        setContentView(R.layout.activity_category_filter);

        initViews();
        setView();
        setListener();
    }



    @Override
    protected String getActivityTitle() {
        return null;
    }

    /**
     * 画面初始化
     */
    @SuppressLint("RtlHardcoded")
    private void setView() {
        goodsform.setMerchPropertyValueCodeList(propertyId);   //属性id的list
        // 获取类目码(一级分类)
        brand = getIntent().getStringExtra(CommonConst.IntentKey.BRAND_CODE);
        LayoutParams p = getWindow().getAttributes();
        DisplayMetrics dm = new DisplayMetrics();
        getWindowManager().getDefaultDisplay().getMetrics(dm);
        // 高度设置为屏幕的屏幕高度- 底部导航栏hight
        p.height = (int) (dm.heightPixels - dm.density * 53);
        // 宽度设置为屏幕的0.8
        p.width = (int) (dm.widthPixels * 0.8);
        // 设置生效
        getWindow().setAttributes(p);
        // 设置靠右对齐
        getWindow().setGravity(Gravity.RIGHT | Gravity.TOP);
        setVisibleTab(); // 显示筛选归类
        //        brandListRequest.setToken(agent.getToken()); // 设置token
        //        brandListRequest.setMerchCategoryCode(code); // 设置一级分类码
        // 请求数据调用获得品牌接口
        //        danluTaskProxy.getTeaBrandList(brandListRequest, brandTeaListener, QueuableTask.PRIORITY_CRITICAL);
        getBrandWithSecCode(code);
        setAacheData(); // 获取缓存对象
    }

    /**
     * 获取返回对象
     */
    private <T> T serializeReturnModel(Class<T> clazz, MerchCategoryListResponse response) {
        Gson gson = new Gson();
        return gson.fromJson(gson.toJson(response.getCategoryItem()), clazz);
    }

    /**
     * 设置缓存数据
     */
    private void setAacheData() {
        ACache aCache = ACache.get(getApplicationContext());
        //noinspection unchecked
        tupleCategory = (Tuple<String, String>) aCache.getAsObject(CommonConst.ACacheComstants.CATEGORY);
        tupleProperty = (CachingArrayList) aCache.getAsObject(CommonConst.ACacheComstants.PROPERTY);
        //noinspection unchecked
        tupleBrand = (Tuple<String, String>) aCache.getAsObject(CommonConst.ACacheComstants.BRAND); // 获取品牌码/名的缓存体
        tuplePrice = aCache.getAsString(CommonConst.ACacheComstants.PRICE);  //获取价格缓存
        Int2 indexs = SerializeCache.getInstance().getCategoryIndexs();
        if (tupleCategory != null) {
            txtTeaSead.setText(tupleCategory.getSecondValue());  //显示茶类子选项
            // 将缓存中类目码设置入筛选条件请求体中
            goodsform.setMerchCategoryCode(tupleCategory.getFirstValue());  //类目id
        }
        if (indexs.y != -1 && (tab.equals(getString(R.string.category_tea_label)))) {
            if (agent.getCategory(indexs.x, indexs.y) == null) {
                return;
            }
            txtTeaSead.setText(agent.getCategory(indexs.x, indexs.y).getName());  //“茶”的二级分类名
        }
        //设置品牌
        if (tupleBrand != null) {
            txtBrandName.setText(tupleBrand.getSecondValue());
        } else {
            String fromTag = agent.getFromTag();
            // 首页点击白酒、葡萄酒、饮料等进入，品牌显示"全部"
            if (fromTag.equals("SelectTypeHeader")) {
                txtBrandName.setText(getString(R.string.category_all_label));
            } else if (indexs.y != -1 && (tab.equals(getString(R.string.category_wine_label)) //点击首页分类-->二级分类直接进入
                    || tab.equals(getString(R.string.category_foreign_wine))
                    || tab.equals(getString(R.string.category_beer))
                    || tab.equals(getString(R.string.category_red_wine)))) {
                if (agent.getCategory(indexs.x, indexs.y) == null) {
                    return;
                }
                txtBrandName.setText(agent.getCategory(indexs.x, indexs.y).getName());
            }
        }
        if (tupleProperty != null) {
            // 选中白酒香型
            if (tab.equals(getResources().getString(R.string.category_wine_label))) {
                String name = tupleProperty.get(0).getThirdValue();
                txtOdorType.setText(name);
            }
            // 选中葡萄酒产地
            if (tab.equals(getResources().getString(R.string.category_red_wine))) {
                String name = tupleProperty.get(0).getThirdValue();
                txtRwPlace.setText(name);
            }
            // 选中茶种
            if (tab.equals(getResources().getString(R.string.category_tea_label))) {
                String name = tupleProperty.get(0).getThirdValue();
                txtTeaSort.setText(name);
            }

            // 选中"饮料"
            if (tab.equals(getString(R.string.category_drinks))) {
                String name = tupleProperty.get(0).getThirdValue();
                secondClassifyCode = tupleProperty.get(0).getSecondValue(); // 未从“分类”二级分类进入时
                if (drinksItem != null) {
                    getBrandWithSecCode(secondClassifyCode);
                }
                txtClassify.setText(name);
            }
            // 选中"粮油"
            if (tab.equals(getString(R.string.category_grain))) {
                String name = tupleProperty.get(0).getThirdValue();
                secondClassifyCode = tupleProperty.get(0).getSecondValue();
                if (grainItem != null) {
                    getBrandWithSecCode(secondClassifyCode);
                }
                txtClassify.setText(name);
            }
            // 选中"副食"
            if (tab.equals(getString(R.string.category_non_staple))) {
                String name = tupleProperty.get(0).getThirdValue();
                secondClassifyCode = tupleProperty.get(0).getSecondValue();
                if (nonStapleItem != null) {
                    getBrandWithSecCode(secondClassifyCode);
                }
                txtClassify.setText(name);
            }
            // 选中"日化用品"
            if (tab.equals(getString(R.string.category_daily_used))) {
                String name = tupleProperty.get(0).getThirdValue();
                secondClassifyCode = tupleProperty.get(0).getSecondValue();
                if (dailyUsedItem != null) {
                    getBrandWithSecCode(secondClassifyCode);
                }
                txtClassify.setText(name);
            }
            // 选中"五金"
            if (tab.equals(getString(R.string.category_hardware))) {
                String name = tupleProperty.get(0).getThirdValue();
                secondClassifyCode = tupleProperty.get(0).getSecondValue();
                if (hardwareItem != null) {
                    getBrandWithSecCode(secondClassifyCode);
                }
                txtClassify.setText(name);
            }
            // 选中"家电"
            if (tab.equals(getString(R.string.category_electric))) {
                String name = tupleProperty.get(0).getThirdValue();
                secondClassifyCode = tupleProperty.get(0).getSecondValue();
                if (electricItem != null) {
                    getBrandWithSecCode(secondClassifyCode);
                }
                txtClassify.setText(name);
            }
            // 选中洋酒
            if (tab.equals(getResources().getString(R.string.category_foreign_wine))) {
                for (int i = 0; i < tupleProperty.size(); i++) {
                    if (tupleProperty.get(i).getFirstValue().equals(FOREIGN_CLASSIFY)) {
                        String classifyName = tupleProperty.get(i).getThirdValue();
                        txtFwClassify.setText(classifyName); // 设置洋酒分类
                    } else if (tupleProperty.get(i).getFirstValue().equals(FOREIGN_COUNTRY)) {
                        String countryName = tupleProperty.get(i).getThirdValue();
                        txtFwCountry.setText(countryName); // 设置洋酒国家
                    }
                }
            }
            // 选中啤酒
            if (tab.equals(getResources().getString(R.string.category_beer))) {
                for (int i = 0; i < tupleProperty.size(); i++) {
                    if (tupleProperty.get(i).getFirstValue().equals(BEER_CLASSIFY)) {
                        String classifyName = tupleProperty.get(i).getThirdValue();
                        txtClassify.setText(classifyName); // 设置啤酒分类
                    } else if (tupleProperty.get(i).getFirstValue().equals(BEER_COUNTRY)) {
                        String countryName = tupleProperty.get(i).getThirdValue();
                        txtBCountry.setText(countryName); // 设置啤酒国家
                    }
                }
            }
        }
        if (tuplePrice != null) {
            txtPrice.setText(tuplePrice);
        }
    }

    /**
     * 获取缓存对象
     */
    private void getAacheData() {
        ACache aCache = ACache.get(getApplicationContext());
        //noinspection unchecked,unchecked
        tupleCategory = (Tuple<String, String>) aCache.getAsObject(CommonConst.ACacheComstants.CATEGORY);
        tupleProperty = (CachingArrayList) aCache.getAsObject(CommonConst.ACacheComstants.PROPERTY);
        //noinspection unchecked
        tupleBrand = (Tuple<String, String>) aCache.getAsObject(CommonConst.ACacheComstants.BRAND);
        tuplePrice = aCache.getAsString(CommonConst.ACacheComstants.PRICE);
        if (tupleCategory != null) {
            txtTeaSead.setText(tupleCategory.getSecondValue());
            // 将缓存中类目码设置入筛选条件请求体中
            goodsform.setMerchCategoryCode(tupleCategory.getFirstValue());
        }
        if (tupleBrand != null) {
            // 将缓存中品牌码设置入筛选条件请求体中
            goodsform.setMerchBrandId(tupleBrand.getFirstValue());
        }
        if (tupleProperty != null) {
            // 白酒，筛选条件请求体中加入“香型”属性
            if (tab.equals(getResources().getString(R.string.category_wine_label))) {
                if (!goodsform.getMerchPropertyValueCodeList().contains(tupleProperty.get(0).getSecondValue())) {
                    goodsform.getMerchPropertyValueCodeList().add(tupleProperty.get(0).getSecondValue());
                }
            }
            // 葡萄酒，筛选条件请求体中加入“产地”属性
            if (tab.equals(getResources().getString(R.string.category_red_wine))) {
                if (!goodsform.getMerchPropertyValueCodeList().contains(tupleProperty.get(0).getSecondValue())) {
                    goodsform.getMerchPropertyValueCodeList().add(tupleProperty.get(0).getSecondValue());
                }
            }
            // "饮料"，筛选条件请求体中加入“分类”属性
            if (tab.equals(getString(R.string.category_drinks))) {
                goodsform.setMerchCategoryCode(tupleProperty.get(0).getSecondValue());  //设置分类码
                secondClassifyCode = tupleProperty.get(0).getSecondValue();
            }
            // "粮油"，筛选条件请求体中加入“分类”属性
            if (tab.equals(getString(R.string.category_grain))) {
                goodsform.setMerchCategoryCode(tupleProperty.get(0).getSecondValue());  //设置分类码
            }
            // "副食"，筛选条件请求体中加入“分类”属性
            if (tab.equals(getString(R.string.category_non_staple))) {
                goodsform.setMerchCategoryCode(tupleProperty.get(0).getSecondValue());  //设置分类码
            }
            //"日化用品"，筛选条件请求体中加入“分类”属性
            if (tab.equals(getString(R.string.category_daily_used))) {
                goodsform.setMerchCategoryCode(tupleProperty.get(0).getSecondValue());  //设置分类码
            }
            //"五金"，筛选条件请求体中加入“分类”属性
            if (tab.equals(getString(R.string.category_hardware))) {
                goodsform.setMerchCategoryCode(tupleProperty.get(0).getSecondValue());  //设置分类码
            }
            //"家电"，筛选条件请求体中加入“分类”属性
            if (tab.equals(getString(R.string.category_electric))) {
                goodsform.setMerchCategoryCode(tupleProperty.get(0).getSecondValue());  //设置分类码
            }
            // 茶，筛选条件请求体中加入“茶种”属性
            if (tab.equals(getResources().getString(R.string.category_tea_label))) {
                if (!goodsform.getMerchPropertyValueCodeList().contains(tupleProperty.get(0).getSecondValue())) {
                    goodsform.getMerchPropertyValueCodeList().add(tupleProperty.get(0).getSecondValue());
                }
            }
            // 洋酒，筛选条件请求体中加入“分类”、“国家”属性
            if (tab.equals(getResources().getString(R.string.category_foreign_wine))) {
                final String code1 = tupleProperty.size() > 0 ? tupleProperty.get(0).getSecondValue() : null;
                //如果商品属性列表有一个值，且筛选条件属性列表中没有此值，则筛选条件属性列表加入这个值
                if (tupleProperty.size() > 0) {
                    if (!goodsform.getMerchPropertyValueCodeList().contains(tupleProperty.get(0).getSecondValue())) {
                        goodsform.getMerchPropertyValueCodeList().add(tupleProperty.size() > 0 ? tupleProperty.get(0).getSecondValue() : null);
                    }
                }
                final String code2 = tupleProperty.size() > 1 ? tupleProperty.get(1).getSecondValue() : null;
                //如果商品属性列表有多个值，且筛选条件属性列表中没有第2个值，则筛选条件属性列表加入第2个值
                if (tupleProperty.size() > 1) {
                    if (!goodsform.getMerchPropertyValueCodeList().contains(tupleProperty.get(1).getSecondValue())) {
                        goodsform.getMerchPropertyValueCodeList().add(tupleProperty.size() > 1 ? tupleProperty.get(1).getSecondValue() : null);
                    }
                }
                checkTextViewIndex(new ArrayList<String>() {
                    {
                        if (code1 != null) {
                            add(code1);
                        }
                        if (code2 != null) {
                            add(code2);
                        }
                    }
                }, new ArrayList<Tuple<List<Tuple<String, String>>, TextView>>() {
                    {
                        add(new Tuple<>(foreignItem.getClassifyTupleList(), txtFwClassify));
                        add(new Tuple<>(foreignItem.getCountryTupleList(), txtFwCountry));
                    }
                });

            }
            // 啤酒，筛选条件请求体中加入“分类”、“国家”属性
            if (tab.equals(getResources().getString(R.string.category_beer))) {
                final String code1 = tupleProperty.size() > 0 ? tupleProperty.get(0).getSecondValue() : null; //
                if (tupleProperty.size() > 0) {
                    if (!goodsform.getMerchPropertyValueCodeList().contains(tupleProperty.get(0).getSecondValue())) {
                        goodsform.getMerchPropertyValueCodeList().add(tupleProperty.size() > 0 ? tupleProperty.get(0).getSecondValue() : null);
                    }
                }

                final String code2 = tupleProperty.size() > 1 ? tupleProperty.get(1).getSecondValue() : null;
                if (tupleProperty.size() > 1) {
                    if (!goodsform.getMerchPropertyValueCodeList().contains(tupleProperty.get(1).getSecondValue())) {
                        goodsform.getMerchPropertyValueCodeList().add(tupleProperty.size() > 1 ? tupleProperty.get(1).getSecondValue() : null);
                    }
                }
                checkTextViewIndex(new ArrayList<String>() {
                    {
                        if (code1 != null) {
                            add(code1);
                        }
                        if (code2 != null) {
                            add(code2);
                        }
                    }
                }, new ArrayList<Tuple<List<Tuple<String, String>>, TextView>>() {
                    {
                        add(new Tuple<>(beerItem.getClassifyTupleList(), txtClassify));
                        add(new Tuple<>(beerItem.getCountryTupleList(), txtBCountry));
                    }
                });
            }
        }
        getPriceACache();
    }


    /**
     * 获取价格缓存
     */
    private void getPriceACache() {
        if (tuplePrice != null) {
            String priceTemp[];
            if (tuplePrice.equals(getString(R.string.category_price_between_label_1))) {
                // 将得到的字符串拆分
                priceTemp = getString(R.string.category_price_between_label_1).split("-");
                // 设置低价
                goodsform.setLowPrice(priceTemp[0]);
                // 设置高价显示
                goodsform.setHighPrice(priceTemp[1]);
            } else if (tuplePrice.equals(getString(R.string.category_price_between_label_2))) {
                // 将得到的字符串拆分
                priceTemp = getString(R.string.category_price_between_label_2).split("-");
                // 设置低价
                goodsform.setLowPrice(priceTemp[0]);
                goodsform.setHighPrice(priceTemp[1]);
            } else if (tuplePrice.equals(getString(R.string.category_price_between_label_3))) {
                priceTemp = getString(R.string.category_price_between_label_3).split("-");
                goodsform.setLowPrice(priceTemp[0]);
                goodsform.setHighPrice(priceTemp[1]);
            } else if (tuplePrice.equals(getString(R.string.category_price_between_label_4))) {
                priceTemp = getString(R.string.category_price_between_label_4).split("-");
                goodsform.setLowPrice(priceTemp[0]);
                goodsform.setHighPrice(priceTemp[1]);
            } else if (tuplePrice.equals(getString(R.string.category_price_between_label_5))) {
                priceTemp = getString(R.string.category_price_between_label_5).split("-");
                goodsform.setLowPrice(priceTemp[0]);
                goodsform.setHighPrice(priceTemp[1]);
            } else if (tuplePrice.equals(getString(R.string.category_price_between_label_6))) {
                priceTemp = getString(R.string.category_price_between_label_6).split("-");
                goodsform.setLowPrice(priceTemp[0]);
                goodsform.setHighPrice(priceTemp[1]);
            } else if (tuplePrice.equals(getString(R.string.category_price_between_label_7))) {
                goodsform.setLowPrice("1000");
            } else {
                if (CommonUtils.isContainChinese(tuplePrice)) {
                    goodsform.setLowPrice(CommonUtils.filterNumber(tuplePrice));
                } else {
                    // 将得到的字符串拆分
                    priceTemp = tuplePrice.split("-");
                    goodsform.setLowPrice(priceTemp[0]);
                    // 设置高价显示
                    goodsform.setHighPrice(priceTemp[1]);
                }
            }
        }
    }

    /**
     * 根据商品的"FirstValue"值设置显示名称
     */
    private void checkTextViewIndex(List<String> codesList, List<Tuple<List<Tuple<String, String>>, TextView>> list) {
        for (int i = 0; i < codesList.size(); i++) {
            String code = codesList.get(i);
            for (int j = 0; j < list.size(); j++) {
                List<Tuple<String, String>> itemList = list.get(j).getFirstValue();
                TextView textView = list.get(j).getSecondValue();

                for (int k = 0; k < itemList.size(); k++) {
                    Tuple<String, String> tuple = itemList.get(k);
                    if (code.equals(tuple.getFirstValue())) {
                        textView.setText(tuple.getSecondValue());
                    }
                }
            }
        }
    }

    /**
     * 显示各类tab
     */
    private void setVisibleTab() {
        brandIntent = getIntent();
        tab = brandIntent.getStringExtra("firstClassify"); //获取商品一级分类名称
        int isChooseAll = brandIntent.getIntExtra("secondaryIndex", -1);
        // 选中白酒
        if (tab.equals(getResources().getString(R.string.category_wine_label))) {
            llytBrand.setVisibility(View.VISIBLE);  // 品牌
            llytOdorType.setVisibility(View.VISIBLE); // 香型
            lineBrand.setVisibility(View.VISIBLE); // 品牌
            lineOdorType.setVisibility(View.VISIBLE); // 香型
            code = getResources().getString(R.string.category_wine_code);  //一级类目码
        }
        // 选中葡萄酒
        if (tab.equals(getResources().getString(R.string.category_red_wine))) {
            llytBrand.setVisibility(View.VISIBLE); //品牌
            llytRwPlace.setVisibility(View.VISIBLE); //产地
            lineBrand.setVisibility(View.VISIBLE);
            lineRwPlace.setVisibility(View.VISIBLE);
            code = getResources().getString(R.string.category_red_wine_code);
        }
        // 选中茶
        if (tab.equals(getResources().getString(R.string.category_tea_label))) {
            llytBrand.setVisibility(View.VISIBLE); // 品牌
            llytTeaSeed.setVisibility(View.VISIBLE); // 茶类
            llytTeaSort.setVisibility(View.VISIBLE); // 茶种
            lineBrand.setVisibility(View.VISIBLE);
            lineTeaSead.setVisibility(View.VISIBLE);
            code = getResources().getString(R.string.category_tea_code);
            lineTeaSort.setVisibility(View.VISIBLE);
        }
        // 选中洋酒
        if (tab.equals(getResources().getString(R.string.category_foreign_wine))) {
            llytBrand.setVisibility(View.VISIBLE); // 品牌
            llytFwClassify.setVisibility(View.VISIBLE); // 洋酒分类
            llytFwCountry.setVisibility(View.VISIBLE); // 洋酒国家
            lineBrand.setVisibility(View.VISIBLE);
            lineFwClassify.setVisibility(View.VISIBLE);
            lineFwCountry.setVisibility(View.VISIBLE);
            code = getResources().getString(R.string.category_foreign_wine_code);
        }
        // 选中啤酒
        if (tab.equals(getResources().getString(R.string.category_beer))) {
            llytBrand.setVisibility(View.VISIBLE); // 品牌
            llytBClassify.setVisibility(View.VISIBLE); // 啤酒分类
            llytBCountry.setVisibility(View.VISIBLE); // 啤酒国家
            lineBrand.setVisibility(View.VISIBLE);
            lineBCountry.setVisibility(View.VISIBLE);
            lineClassify.setVisibility(View.VISIBLE);
            code = getResources().getString(R.string.category_beer_code); // "C01L0104"
            Log.d("llq", "setVisibleTab: " + code);
        }
        // 选中 "饮料"
        if (tab.equals(getString(R.string.category_drinks))) {
            llytBrand.setVisibility(View.VISIBLE); // 品牌
            if (isChooseAll == -1) {
                llytBClassify.setVisibility(View.VISIBLE); // 借用啤酒分类
                lineClassify.setVisibility(View.VISIBLE);
                code = getString(R.string.category_code_drinks);   // "C01X01"
            } else {
                code = getIntent().getStringExtra(CommonConst.IntentKey.SECOND_CLASSIFY_CODE); // 获取二级分类码
            }
            lineBrand.setVisibility(View.VISIBLE);
        }
        // 选中"粮油"
        if (tab.equals(getString(R.string.category_grain))) {
            llytBrand.setVisibility(View.VISIBLE); // 品牌
            if (isChooseAll == -1) {
                llytBClassify.setVisibility(View.VISIBLE); // 借用啤酒分类
                lineClassify.setVisibility(View.VISIBLE);
                code = getString(R.string.category_code_grain); // "C01G01"
            } else {
                code = getIntent().getStringExtra(CommonConst.IntentKey.SECOND_CLASSIFY_CODE); // 获取二级分类码
            }
            lineBrand.setVisibility(View.VISIBLE);
        }
        // 选中 "副食"
        if (tab.equals(getString(R.string.category_non_staple))) {
            llytBrand.setVisibility(View.VISIBLE); // 品牌
            if (isChooseAll == -1) {
                llytBClassify.setVisibility(View.VISIBLE); // 借用啤酒分类
                lineClassify.setVisibility(View.VISIBLE);
                code = getString(R.string.category_code_non_staple);   // "C01F01"
            } else {
                code = getIntent().getStringExtra(CommonConst.IntentKey.SECOND_CLASSIFY_CODE); // 获取二级分类码
            }
            lineBrand.setVisibility(View.VISIBLE);
        }
        // 选中"日化用品"
        if (tab.equals(getString(R.string.category_daily_used))) {
            llytBrand.setVisibility(View.VISIBLE); // 品牌
            if (isChooseAll == -1) {
                llytBClassify.setVisibility(View.VISIBLE); // 借用啤酒分类
                lineClassify.setVisibility(View.VISIBLE);
                code = getString(R.string.category_code_daily_used);  // "C01P01"
            } else {
                code = getIntent().getStringExtra(CommonConst.IntentKey.SECOND_CLASSIFY_CODE); // 获取二级分类码
            }
            lineBrand.setVisibility(View.VISIBLE);
        }
        // 选中"五金"
        if (tab.equals(getString(R.string.category_hardware))) {
            llytBrand.setVisibility(View.VISIBLE); // 品牌
            if (isChooseAll == -1) {
                llytBClassify.setVisibility(View.VISIBLE); // 借用啤酒分类
                lineClassify.setVisibility(View.VISIBLE);
                code = getString(R.string.category_code_hardware);  // "C01H01"
            } else {
                code = getIntent().getStringExtra(CommonConst.IntentKey.SECOND_CLASSIFY_CODE); // 获取二级分类码
            }
            lineBrand.setVisibility(View.VISIBLE);
        }
        // 选中"家电"
        if (tab.equals(getString(R.string.category_electric))) {
            llytBrand.setVisibility(View.VISIBLE); // 品牌
            if (isChooseAll == -1) {
                llytBClassify.setVisibility(View.VISIBLE); // 借用啤酒分类
                lineClassify.setVisibility(View.VISIBLE);
                code = getString(R.string.category_code_electric);  // "C01J01"
            } else {
                code = getIntent().getStringExtra(CommonConst.IntentKey.SECOND_CLASSIFY_CODE); // 获取二级分类码
            }
            lineBrand.setVisibility(View.VISIBLE);
        }
        // 选中"其它"
        if (tab.equals(getString(R.string.category_others))) {
            llytBClassify.setVisibility(View.VISIBLE); //借用啤酒分类
            lineClassify.setVisibility(View.VISIBLE);
            code = getString(R.string.category_code_others);  // "C01X0101"
        }
    }

    /**
     * 设置监听
     */
    private void setListener() {
        // 取消按钮监听
        llytCancel.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                finish();
            }
        });
        // 确定按钮监听
        llytOk.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                getAacheData();
                getPriceACache(); // 获取价格缓存
                Intent intent = new Intent();
                Bundle bundle = new Bundle(); // 初始化传值对象
                //首页点击二级分类进入，而未继续点击品牌时传值
                Int2 indexs = SerializeCache.getInstance().getCategoryIndexs();
                if (indexs.y != -1 && (tab.equals(getString(R.string.category_wine_label)) || tab.equals(getString(R.string.category_foreign_wine)) || tab.equals(getString(R.string.category_beer)) || tab.equals(getString(R.string.category_red_wine)))) {
                    if (TextUtils.isEmpty(goodsform.getMerchBrandId()) && agent.getFromTag().equals("CategoryHolder")) {
                        if (agent.getCategory(indexs.x) == null || null == agent.getCategory (indexs.x, indexs.y)) {
                            return;
                        }
                        String brandCode = agent.getCategory(indexs.x, indexs.y).getCode();
                        goodsform.setMerchBrandId(brandCode);
                    }
                }
                bundle.putSerializable("form", goodsform); // 把请求对象存入传值对象
                intent.putExtras(bundle); // 把传值对象存入意图对象
                // 把价格区间存入意图对象
                intent.putExtra(CommonConst.IntentKey.PRICE_RANGE, txtPrice.getText().toString());
                // 把品牌名存入意图对象
                intent.putExtra(CommonConst.IntentKey.BRAND_NAME, txtBrandName.getText().toString());
                setResult(RESULT_OK, intent);
                finish(); // 本画面结束
            }
        });

        // 价格按钮点击事件监听
        llytPrice.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // 初始化意图对象
                Intent intent = new Intent();
                Int2 indexs = SerializeCache.getInstance().getCategoryIndexs();
                //选了"家电"，且选择了具体分类
                if (tab.equals(getString(R.string.category_electric)) && indexs.y != -1) {
                    if (agent.getCategory(indexs.x, indexs.y) == null) {
                        return;
                    }
                    String name = agent.getCategory(indexs.x, indexs.y).getName();  //二级分类名
                    if (!TextUtils.isEmpty(name) && name.equals("大家电")) {
                        intent.putExtra("priseInterval", "highPrice");
                    } else {
                        intent.putExtra("priseInterval", "lowPrice");
                    }
                    //首页选择"饮料"||"粮油"||"副食"，&& 选择全部
                } else if ((tab.equals(getString(R.string.category_drinks))
                        || tab.equals(getString(R.string.category_grain))
                        || tab.equals(getString(R.string.category_non_staple)))
                        && indexs.y == -1) {
                    intent.putExtra("priseInterval", "midPrice");
                } else if ((tab.equals(getString(R.string.category_drinks))
                        || tab.equals(getString(R.string.category_grain))
                        || tab.equals(getString(R.string.category_non_staple)))
                        && indexs.y != -1) {        //首页选择"饮料"||"粮油"||"副食"，&& 未选择全部
                    intent.putExtra("priseInterval", "lowPrice");
                    //"日化用品" || "五金" || "其它"
                } else if (tab.equals(getString(R.string.category_daily_used)) || tab.equals(getString(R.string.category_hardware)) || tab.equals(getString(R.string.category_others))) {
                    intent.putExtra("priseInterval", "lowPrice");
                }
                // 设置要跳转的画面
                intent.setClass(CategoryFilterActivity.this, CategoryPriceFilterActivity.class);
                // 设置跳转参数
                intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
                // 跳转
                CategoryFilterActivity.this.startActivityForResult(intent, CommonConst.IntentKey.PRICE_REQUEST_CODE);
            }
        });

        // 产地点击事件（葡萄酒）
        llytRwPlace.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View arg0) {
                if (redWineItem == null) {
                    return;
                }
                Intent intent = new Intent();
                Bundle bundle = new Bundle();
                bundle.putString(CommonConst.IntentKey.RED_WINE_PLACE, CommonConst.IntentKey.RED_WINE_PLACE);
                bundle.putSerializable(CommonConst.IntentKey.RED_WINE_CONSTANT, redWineItem);
                intent.putExtras(bundle);
                intent.setClass(CategoryFilterActivity.this, CategoryTeaBrandFilterActivity.class);
                intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
                CategoryFilterActivity.this.startActivityForResult(intent, CommonConst.IntentKey.RED_WINE_REQUEST_CODE);
            }
        });

        // 洋酒分类点击事件
        llytFwClassify.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View arg0) {
                if (foreignItem == null) {
                    return;
                }
                Intent intent = new Intent();
                Bundle bundle = new Bundle();
                bundle.putString(FOREIGN_CLASSIFY, FOREIGN_CLASSIFY);
                bundle.putSerializable(CommonConst.IntentKey.FOREIGN_CLASSIFY_CONSTANT, foreignItem);
                intent.putExtras(bundle);
                intent.setClass(CategoryFilterActivity.this, CategoryTeaBrandFilterActivity.class);
                intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
                CategoryFilterActivity.this.startActivityForResult(intent, CommonConst.IntentKey.FOREIGN_CLASSIFY_REQUEST_CODE);
            }
        });

        // 洋酒国家点击事件
        llytFwCountry.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View arg0) {
                if (foreignItem == null) {
                    return;
                }
                Intent intent = new Intent();
                Bundle bundle = new Bundle();
                bundle.putString(FOREIGN_COUNTRY, FOREIGN_COUNTRY);
                bundle.putSerializable(CommonConst.IntentKey.FOREIGN_COUNTRY_CONSTANT, foreignItem);
                intent.putExtras(bundle);
                intent.setClass(CategoryFilterActivity.this, CategoryTeaBrandFilterActivity.class);
                intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
                CategoryFilterActivity.this.startActivityForResult(intent, CommonConst.IntentKey.FOREIGN_COUNTRY_REQUEST_CODE);
            }
        });

        // 啤酒国家点击事件
        llytBCountry.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View arg0) {
                if (beerItem == null) {
                    return;
                }
                Intent intent = new Intent();
                Bundle bundle = new Bundle();
                bundle.putString(BEER_COUNTRY, BEER_COUNTRY);
                bundle.putSerializable(CommonConst.IntentKey.BEER_COUNTRY_CONSTANT, beerItem);
                intent.putExtras(bundle);
                intent.setClass(CategoryFilterActivity.this, CategoryTeaBrandFilterActivity.class);
                intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
                CategoryFilterActivity.this.startActivityForResult(intent, CommonConst.IntentKey.BEER_COUNTRY_REQUEST_CODE);
            }
        });

        // 啤酒、饮料、副食等分类点击事件
        llytBClassify.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View arg0) {
                Intent intent = new Intent();
                Bundle bundle = new Bundle();
                // "饮料"
                if (brandIntent.getStringExtra("firstClassify").equals(getString(R.string.category_drinks))) {
                    if (drinksItem == null) {
                        return;
                    }
                    bundle.putString("分类", getString(R.string.category_drinks)); // "饮料"
                    bundle.putString("lastChoose", txtClassify.getText().toString());  //上次选择的分类
                    bundle.putSerializable(CommonConst.IntentKey.DRINKS_CLASSIFY_CONSTANT, drinksItem);  //("drinksClassify",mDrinksItem)
                    intent.putExtras(bundle);
                    intent.setClass(CategoryFilterActivity.this, GoodsClassifyActivity.class); // 设置要跳转的页面
                    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); // 设置跳转类型参数
                    CategoryFilterActivity.this.startActivityForResult(intent,
                            CommonConst.IntentKey.DRINKS_CLASSIFY_REQUEST_CODE);  //跳转，设置请求码
                    // "粮油"
                } else if (brandIntent.getStringExtra("firstClassify").equals(getString(R.string.category_grain))) {
                    if (grainItem == null) {
                        return;
                    }
                    bundle.putString("分类", getString(R.string.category_grain)); // "粮油"
                    bundle.putString("lastChoose", txtClassify.getText().toString());  // 上次选择的分类
                    bundle.putSerializable(CommonConst.IntentKey.GRAIN_CLASSIFY_CONSTANT, grainItem);  // ("grainClassify",mGrainItem)
                    intent.putExtras(bundle);
                    intent.setClass(CategoryFilterActivity.this, GoodsClassifyActivity.class);
                    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); // 设置跳转类型参数
                    CategoryFilterActivity.this.startActivityForResult(intent,
                            CommonConst.IntentKey.GRAIN_CLASSIFY_REQUEST_CODE);  // 跳转，设置请求码
                    // "副食"
                } else if (brandIntent.getStringExtra("firstClassify").equals(getString(R.string.category_non_staple))) {
                    if (nonStapleItem == null) {
                        return;
                    }
                    bundle.putString("分类", getString(R.string.category_non_staple)); // "副食"
                    bundle.putString("lastChoose", txtClassify.getText().toString());  //上次选择的分类
                    bundle.putSerializable(CommonConst.IntentKey.NON_STAPLE_CLASSIFY_CONSTANT, nonStapleItem);  //("nonStapleClassify",mNonStapleItem)
                    intent.putExtras(bundle);
                    intent.setClass(CategoryFilterActivity.this, GoodsClassifyActivity.class);
                    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); // 设置跳转类型参数
                    CategoryFilterActivity.this.startActivityForResult(intent,
                            CommonConst.IntentKey.NON_STAPLE_CLASSIFY_REQUEST_CODE); // 跳转,设置请求码
                    // "日化用品"
                } else if (brandIntent.getStringExtra("firstClassify").equals(getString(R.string.category_daily_used))) {
                    if (dailyUsedItem == null) {
                        return;
                    }
                    bundle.putString("分类", getString(R.string.category_daily_used)); // "日化用品"
                    bundle.putString("lastChoose", txtClassify.getText().toString());  //上次选择的分类
                    bundle.putSerializable(CommonConst.IntentKey.DAILY_USED_CLASSIFY_CONSTANT, dailyUsedItem);  //("dailyUsedClassify",mDailyUsedItem)
                    intent.putExtras(bundle);
                    intent.setClass(CategoryFilterActivity.this, GoodsClassifyActivity.class);
                    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); // 设置跳转类型参数
                    CategoryFilterActivity.this.startActivityForResult(intent,
                            CommonConst.IntentKey.DAILY_USED_CLASSIFY_REQUEST_CODE); // 跳转,设置请求码14
                    // "五金"
                } else if (brandIntent.getStringExtra("firstClassify").equals(getString(R.string.category_hardware))) {
                    if (hardwareItem == null) {
                        return;
                    }
                    bundle.putString("分类", "五金");
                    bundle.putString("lastChoose", txtClassify.getText().toString());  // 上次选择的分类
                    bundle.putSerializable(CommonConst.IntentKey.HARDWARE_CLASSIFY_CONSTANT, hardwareItem);  // ("hardwareClassify",mHardwareItem)
                    intent.putExtras(bundle);
                    intent.setClass(CategoryFilterActivity.this, GoodsClassifyActivity.class);
                    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); // 设置跳转类型参数
                    CategoryFilterActivity.this.startActivityForResult(intent,
                            CommonConst.IntentKey.HARDWARE_CLASSIFY_REQUEST_CODE); // 跳转,设置请求码15
                    // "家电"
                } else if (brandIntent.getStringExtra("firstClassify").equals(getString(R.string.category_electric))) {
                    if (electricItem == null) {
                        return;
                    }
                    bundle.putString("分类", getString(R.string.category_electric)); // "家电"
                    bundle.putString("lastChoose", txtClassify.getText().toString());  // 上次选择的分类
                    bundle.putSerializable(CommonConst.IntentKey.ELECTRIC_CLASSIFY_CONSTANT, electricItem);  // ("electricClassify",mElectricItem)
                    intent.putExtras(bundle);
                    intent.setClass(CategoryFilterActivity.this, GoodsClassifyActivity.class);
                    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); // 设置跳转类型参数
                    CategoryFilterActivity.this.startActivityForResult(intent,
                            CommonConst.IntentKey.ELECTRIC_CLASSIFY_REQUEST_CODE); // 跳转,设置请求码16
                    // "其它"
                } else if (brandIntent.getStringExtra("firstClassify").equals(getString(R.string.category_others))) {
                    if (othersItem == null) {
                        Toast.makeText(CategoryFilterActivity.this, "暂无数据", Toast.LENGTH_SHORT).show();
                        return;
                    }
                    bundle.putString("分类", getString(R.string.category_others)); // "其它"
                    bundle.putString("lastChoose", txtClassify.getText().toString());  //上次选择的分类
                    bundle.putSerializable(CommonConst.IntentKey.OTHERS_CLASSIFY_CONSTANT, othersItem);  //("othersClassify",othersItem)
                    intent.putExtras(bundle);
                    intent.setClass(CategoryFilterActivity.this, GoodsClassifyActivity.class);
                    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); // 设置跳转类型参数
                    CategoryFilterActivity.this.startActivityForResult(intent,
                            CommonConst.IntentKey.OTHERS_CLASSIFY_REQUEST_CODE); // 跳转,设置请求码13
                    // "啤酒"
                } else if (brandIntent.getStringExtra("firstClassify").equals(getString(R.string.category_beer))) {
                    if (beerItem == null) {
                        return;
                    }
                    bundle.putString(BEER_CLASSIFY, BEER_CLASSIFY);
                    bundle.putSerializable(CommonConst.IntentKey.BEER_CLASSIFY_CONSTANT, beerItem);
                    intent.putExtras(bundle);
                    intent.setClass(CategoryFilterActivity.this, CategoryTeaBrandFilterActivity.class);
                    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
                    CategoryFilterActivity.this.startActivityForResult(intent, CommonConst.IntentKey.BEER_CLASSIFY_REQUEST_CODE);
                }
            }
        });

        // 香型点击事件
        llytOdorType.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View arg0) {
                if (wineItem == null) {
                    return;
                }
                Intent intent = new Intent();
                Bundle bundle = new Bundle();
                bundle.putString(CommonConst.IntentKey.ORDOR_TYPE, CommonConst.IntentKey.ORDOR_TYPE);
                bundle.putSerializable(CommonConst.IntentKey.ORDOR_CONSTANT, wineItem);
                intent.putExtras(bundle);
                intent.setClass(CategoryFilterActivity.this, CategoryTeaBrandFilterActivity.class);
                intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
                CategoryFilterActivity.this.startActivityForResult(intent, CommonConst.IntentKey.ORDOR_REQUEST_CODE);

            }
        });


        // 茶类点击事件
        llytTeaSeed.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View arg0) {
                if (teaItem == null) {
                    return;
                }
                Intent intent = new Intent();
                Bundle bundle = new Bundle();
                bundle.putString(CommonConst.IntentKey.TEA_SEED, TEA_SEED);
                bundle.putSerializable(CommonConst.IntentKey.TEA_SEED_CONSTANT, teaItem);
                intent.putExtras(bundle);
                intent.setClass(CategoryFilterActivity.this, CategoryTeaBrandFilterActivity.class);
                intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
                CategoryFilterActivity.this.startActivityForResult(intent, CommonConst.IntentKey.TEA_SEED_REQUEST_CODE);
            }
        });

        // 茶种点击事件
        llytTeaSort.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View arg0) {
                if (brandIntent.getStringExtra("firstClassify").equals(getResources().getString(R.string.category_tea_label)) && (txtTeaSead.getText().equals(getResources().getString(R.string.category_all_label)) || txtTeaSort.getText().equals(""))) {
                    ToastUtil.getInstance().show(getString(R.string.choose_tea_seed_tips));
                    return;
                }
                Intent intent = new Intent();
                Bundle bundle = new Bundle();
                bundle.putString(CommonConst.IntentKey.TEA_SORT, TEA_SORT);
                bundle.putSerializable(CommonConst.IntentKey.TEA_SORT_CONSTANT, teaItem);
                intent.putExtras(bundle);
                intent.setClass(CategoryFilterActivity.this, CategoryTeaBrandFilterActivity.class);
                intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
                CategoryFilterActivity.this.startActivityForResult(intent, CommonConst.IntentKey.TEA_SORT_REQUEST_CODE);
            }
        });

        // 品牌点击事件监听
        llytBrand.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                if (brandIntent.getStringExtra("firstClassify").equals(getResources().getString(R.string.category_tea_label)) && (txtTeaSead.getText().equals("全部") || txtTeaSort.getText().equals(""))) {
                    ToastUtil.getInstance().show(getString(R.string.choose_tea_seed_to_brand));
                    return;
                }
                //是否点击了 "饮料" || "粮油" || "副食" || "日化用品" || "五金" || "家电"  的分类
                boolean clickable = ((brandIntent.getStringExtra("firstClassify").equals(getString(R.string.category_drinks))
                        || brandIntent.getStringExtra("firstClassify").equals(getString(R.string.category_grain))
                        || brandIntent.getStringExtra("firstClassify").equals(getString(R.string.category_non_staple))
                        || brandIntent.getStringExtra("firstClassify").equals(getString(R.string.category_daily_used))
                        || brandIntent.getStringExtra("firstClassify").equals(getString(R.string.category_hardware))
                        || brandIntent.getStringExtra("firstClassify").equals(getString(R.string.category_electric)))
                        && txtClassify.getText().equals(getString(R.string.all_delivery_search_label)));
                if ((llytBClassify.getVisibility() == View.VISIBLE) && clickable) {
                    ToastUtil.getInstance().show(R.string.choose_classify_tips);  // "请选择分类再选择品牌"
                    return;
                }
                Intent intent = new Intent();
                Bundle bundle = new Bundle();
                // 选中茶
                if (brandIntent.getStringExtra("firstClassify").equals(getResources().getString(R.string.category_tea_label))) {
                    if (teaItem == null) {
                        return;
                    }
                    intent.setClass(CategoryFilterActivity.this, CategoryTeaBrandFilterActivity.class);
                    bundle.putSerializable(CommonConst.IntentKey.TEA_BRAND_CONSTANT, teaItem);
                    bundle.putString(CommonConst.IntentKey.BRAND_CODE, brand);
                    bundle.putString(CommonConst.IntentKey.BRAND_NAME, CommonConst.IntentKey.TEA_WORD); // 传入茶名("brand_name","茶")
                } else if (brandIntent.getStringExtra("firstClassify").equals(getResources().getString(R.string.category_wine_label))) { // 白酒
                    if (wineItem == null) {
                        return;
                    }
                    bundle.putString(CommonConst.IntentKey.BRAND_CODE, brand); // 一级分类码
                    bundle.putString(CommonConst.IntentKey.BRAND_NAME, CommonConst.IntentKey.WINE_WORD);
                    bundle.putSerializable(CommonConst.IntentKey.WINE_WORD, wineItem);

                } else if (brandIntent.getStringExtra("firstClassify").equals(getResources().getString(R.string.category_red_wine))) { // 葡萄酒
                    if (redWineItem == null) {
                        return;
                    }
                    bundle.putString(CommonConst.IntentKey.BRAND_CODE, brand);    //一级分类码
                    bundle.putString(CommonConst.IntentKey.BRAND_NAME, CommonConst.IntentKey.RED_WINE_WORD);// 传入葡萄酒名
                    bundle.putSerializable(CommonConst.IntentKey.RED_WINE_WORD, redWineItem);
                } else if (brandIntent.getStringExtra("firstClassify").equals(getString(R.string.category_others))) { // 其它
                    if (othersItem == null) {
                        return;
                    }
                    bundle.putString(CommonConst.IntentKey.BRAND_CODE, brand);   //("brand_code",brand)  一级分类码
                    bundle.putString(CommonConst.IntentKey.BRAND_NAME, CommonConst.IntentKey.OTHER_WINE_WORD);// 传入其他饮品名
                    bundle.putSerializable(CommonConst.IntentKey.OTHER_WINE_WORD, othersItem);
                } else if (brandIntent.getStringExtra("firstClassify").equals(getResources().getString(R.string.category_foreign_wine))) { // 洋酒
                    if (foreignItem == null) {
                        return;
                    }
                    bundle.putString(CommonConst.IntentKey.BRAND_CODE, brand);   //("brand_code",brand)  一级分类码
                    bundle.putString(CommonConst.IntentKey.BRAND_NAME, CommonConst.IntentKey.FOREIGN_WINE_WORD);// 传入洋酒
                    bundle.putSerializable(CommonConst.IntentKey.FOREIGN_WINE_WORD, foreignItem);
                } else if (brandIntent.getStringExtra("firstClassify").equals(getResources().getString(R.string.category_beer))) { // 啤酒
                    if (beerItem == null) {
                        return;
                    }
                    bundle.putString(CommonConst.IntentKey.BRAND_CODE, brand);   // ("brand_code",brand)  一级分类码
                    bundle.putString(CommonConst.IntentKey.BRAND_NAME, CommonConst.IntentKey.BEER_WORD); // 传入啤酒
                    bundle.putSerializable(CommonConst.IntentKey.BEER_WORD, beerItem);
                } else if (brandIntent.getStringExtra("firstClassify").equals(getString(R.string.category_drinks))) { // "饮料"
                    if (drinksBrand == null) {
                        return;
                    }
                    bundle.putString(CommonConst.IntentKey.BRAND_CODE, brand);   // ("brand_code",brand)  一级分类码
                    bundle.putString(CommonConst.IntentKey.BRAND_NAME, getString(R.string.category_drinks)); // "饮料"
                    bundle.putSerializable("饮料", drinksBrand);
                } else if (brandIntent.getStringExtra("firstClassify").equals(getString(R.string.category_grain))) { // "粮油"
                    if (grainBrand == null) {
                        return;
                    }
                    bundle.putString(CommonConst.IntentKey.BRAND_CODE, brand);   //("brand_code",brand)  一级分类码
                    bundle.putString(CommonConst.IntentKey.BRAND_NAME, getString(R.string.category_grain)); // "粮油"
                    bundle.putSerializable("粮油", grainBrand);
                } else if (brandIntent.getStringExtra("firstClassify").equals(getString(R.string.category_non_staple))) { // "副食"
                    if (nonStapleBrand == null) {
                        return;
                    }
                    bundle.putString(CommonConst.IntentKey.BRAND_CODE, brand);   //("brand_code",brand)  一级分类码
                    bundle.putString(CommonConst.IntentKey.BRAND_NAME, getString(R.string.category_non_staple)); // "副食"
                    bundle.putSerializable("副食", nonStapleBrand);
                } else if (brandIntent.getStringExtra("firstClassify").equals(getString(R.string.category_daily_used))) { // "日化用品"
                    if (dailyUsedBrand == null) {
                        return;
                    }
                    bundle.putString(CommonConst.IntentKey.BRAND_CODE, brand);   //("brand_code",brand)  一级分类码
                    bundle.putString(CommonConst.IntentKey.BRAND_NAME, getString(R.string.category_daily_used)); // "日化用品"
                    bundle.putSerializable("日化用品", dailyUsedBrand);
                } else if (brandIntent.getStringExtra("firstClassify").equals(getString(R.string.category_hardware))) { // "五金"
                    if (hardwareBrand == null) {
                        return;
                    }
                    bundle.putString(CommonConst.IntentKey.BRAND_CODE, brand);   //("brand_code",brand)  一级分类码
                    bundle.putString(CommonConst.IntentKey.BRAND_NAME, getString(R.string.category_hardware)); // "五金"
                    bundle.putSerializable("五金", hardwareBrand);
                } else if (brandIntent.getStringExtra("firstClassify").equals(getString(R.string.category_electric))) { // "家电"
                    if (electricBrand == null) {
                        return;
                    }
                    bundle.putString(CommonConst.IntentKey.BRAND_CODE, brand);   //("brand_code",brand)  一级分类码
                    bundle.putString(CommonConst.IntentKey.BRAND_NAME, getString(R.string.category_electric));  // "家电"
                    bundle.putSerializable("家电", electricBrand);
                }
                // 设置要跳转的页面
                intent.setClass(CategoryFilterActivity.this, CategoryTeaBrandFilterActivity.class);
                intent.putExtras(bundle);
                // 设置跳转类型参数
                intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
                CategoryFilterActivity.this.startActivityForResult(intent, CommonConst.IntentKey.BRAND_REQUEST_CODE);
            }
        });
    }

    /**
     * 啤酒国家、分类，洋酒国家、分类用；用于设置选择的属性
     */
    private void resolvePropertyCodeList() {
        ACache aCache = ACache.get(getApplicationContext());
        final List<ThreeTuple<?, ?, ?>> cachingPropertyList = (List<ThreeTuple<?, ?, ?>>) (aCache.getAsObject(CommonConst.ACacheComstants.PROPERTY) == null ? new ArrayList<ThreeTuple<?, ?, ?>>() : aCache.getAsObject(CommonConst.ACacheComstants.PROPERTY));
        for (int i = 0; i < cachingPropertyList.size(); i++) {
            if (cachingPropertyList.get(i).getThirdValue().equals(getResources().getString(R.string.category_all_label))) {
                cachingPropertyList.remove(i);
                i--;
            }
        }
        goodsform.getMerchPropertyValueCodeList().clear();
        for (int i = 0; i < cachingPropertyList.size(); i++) {
            goodsform.getMerchPropertyValueCodeList().add(cachingPropertyList.get(i).getSecondValue().toString());
        }
    }

    /**
     * 实现onTouchEvent触屏函数但点击屏幕时销毁本Activity
     */
    public boolean onTouchEvent(MotionEvent event) {
        finish();
        return true;
    }

    @SuppressLint("SetTextI18n")
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == 0 && resultCode == RESULT_OK) {
            String priceType = data.getStringExtra("price_type"); // 得到价格类型
            // 如果价格类型等于8
            if ("8".equals(priceType)) {
                goodsform.setHighPrice(data.getStringExtra(CommonConst.IntentKey.HIGH_PRICE)); // 设置请求类对象的高价
                goodsform.setLowPrice(data.getStringExtra(CommonConst.IntentKey.LOW_PRICE)); // 设置请求类对象的低价
                if (data.getStringExtra("allPrice") != null) {
                    txtPrice.setText(data.getStringExtra("allPrice"));
                    goodsform.setHighPrice(null); // 设置请求对象高价参数为空
                    goodsform.setLowPrice(null);  // 设置请求对象低价参数位空
                    CommonUtils.cachingPrice(getApplicationContext(), txtPrice.getText().toString());
                    return;
                }
                // 如果高价为null
                if ("null".equals(data.getStringExtra(CommonConst.IntentKey.HIGH_PRICE))) {
                    // 低价为null
                    if ("null".equals(data.getStringExtra(CommonConst.IntentKey.LOW_PRICE))) {
                        // 设置价格显示文本为显示全部
                        txtPrice.setText(getString(R.string.category_all_label));
                        // 设置请求对象高价参数为空
                        goodsform.setHighPrice(null);
                        // 设置请求对象低价参数位空
                        goodsform.setLowPrice(null);
                    } else {
                        // 设置价格显示文本为低价以上
                        txtPrice.setText(String.valueOf(Integer.parseInt(data.getStringExtra(CommonConst.IntentKey.LOW_PRICE))) + getString(R.string.category_price_above_label));
                        // 设置请求对象高价参数为空
                        goodsform.setHighPrice(null);
                    }

                } else {
                    // 都不为null，价格正常显示为低价-高价
                    txtPrice.setText(String.valueOf(Integer.parseInt(data.getStringExtra(CommonConst.IntentKey.LOW_PRICE))) + "-" + String.valueOf(Integer.parseInt(data.getStringExtra(CommonConst.IntentKey.HIGH_PRICE))));
                }
            }
            CommonUtils.cachingPrice(getApplicationContext(), txtPrice.getText().toString());  //价格放入缓存
        } else if (requestCode == CommonConst.IntentKey.BRAND_REQUEST_CODE        // 品牌
                && resultCode == RESULT_OK) {
            String brandName = data.getStringExtra(CommonConst.IntentKey.BRAND_NAME);
            if (!brandName.equals("null")) {
                txtBrandName.setText(brandName);
            } else {
                txtBrandName.setText(getResources().getString(R.string.category_all_label));
                return;
            }
            goodsform.setMerchBrandId(data.getStringExtra("TEABRANDITEM"));    //将请求体中品牌码设置
        } else if (requestCode == CommonConst.IntentKey.TEA_SEED_REQUEST_CODE && resultCode == RESULT_OK) { // 茶类
            String brandName = data.getStringExtra(CommonConst.IntentKey.TEA_SEED);  // 得到茶类名
            if (!brandName.equals("null")) {
                if (!TextUtils.isEmpty(lastTea) && lastTea.equals(brandName)) {
                    //清除 茶种 & 品牌 & 价格

                } else {
                    goodsform.getMerchPropertyValueCodeList().clear();
                    ACache aCache = ACache.get(getApplicationContext());
                    aCache.remove(CommonConst.ACacheComstants.BRAND);
                    aCache.remove(CommonConst.ACacheComstants.PROPERTY);
                    txtTeaSort.setText(getResources().getString(R.string.category_all_label));
                    txtBrandName.setText(getResources().getString(R.string.category_all_label));
                }
                txtTeaSead.setText(brandName);
            } else {
                txtTeaSead.setText(getResources().getString(R.string.category_all_label));
            }
            lastTea = brandName;
            goodsform.setMerchCategoryCode(data.getStringExtra("TEACODE"));  // 请求体设置茶类码
        } else if (requestCode == CommonConst.IntentKey.TEA_SORT_REQUEST_CODE && resultCode == RESULT_OK) { // 茶种
            String brandName = data.getStringExtra(CommonConst.IntentKey.TEA_SORT);
            if (!brandName.equals("null")) {
                txtTeaSort.setText(brandName);
            } else {
                txtTeaSort.setText(getResources().getString(R.string.category_all_label));
            }
            // 和传过来的值不相等，则添加
            if (!goodsform.getMerchPropertyValueCodeList().contains(data.getStringExtra("TEASORT"))) {
                goodsform.getMerchPropertyValueCodeList().add(data.getStringExtra("TEASORT"));
            }
            if (data.getStringExtra("TEASORT").equals("null")) {    //选择的全部
                goodsform.getMerchPropertyValueCodeList().removeAll(goodsform.getMerchPropertyValueCodeList());
            }
        } else if (requestCode == CommonConst.IntentKey.ORDOR_REQUEST_CODE && resultCode == RESULT_OK) { // 香型
            String brandName = data.getStringExtra(CommonConst.IntentKey.ORDOR_TYPE); // 香型名称
            if (!brandName.equals("null")) {
                txtOdorType.setText(brandName);
            } else {
                txtOdorType.setText(getResources().getString(R.string.category_all_label));
            }
            // 和传过来香型码不相等，则添加
            if (!goodsform.getMerchPropertyValueCodeList().contains(data.getStringExtra(CommonConst.IntentKey.ORDOR_CONSTANT))) {
                goodsform.getMerchPropertyValueCodeList().add(data.getStringExtra(CommonConst.IntentKey.ORDOR_CONSTANT));
            }
        } else if (requestCode == CommonConst.IntentKey.DRINKS_CLASSIFY_REQUEST_CODE && resultCode == RESULT_OK) {
            // 饮料分类
            refreshViewAndData(data);
        } else if (requestCode == CommonConst.IntentKey.GRAIN_CLASSIFY_REQUEST_CODE && resultCode == RESULT_OK) {
            // 粮油分类请求码
            refreshViewAndData(data);
        } else if (requestCode == CommonConst.IntentKey.NON_STAPLE_CLASSIFY_REQUEST_CODE && resultCode == RESULT_OK) {
            // 副食分类请求码
            refreshViewAndData(data);
        } else if (requestCode == CommonConst.IntentKey.DAILY_USED_CLASSIFY_REQUEST_CODE && resultCode == RESULT_OK) {
            // 日化用品分类请求码
            refreshViewAndData(data);
        } else if (requestCode == CommonConst.IntentKey.HARDWARE_CLASSIFY_REQUEST_CODE && resultCode == RESULT_OK) {
            // 五金分类请求码
            refreshViewAndData(data);
        } else if (requestCode == CommonConst.IntentKey.ELECTRIC_CLASSIFY_REQUEST_CODE && resultCode == RESULT_OK) {
            // 家电分类请求码
            refreshViewAndData(data);
        } else if (requestCode == CommonConst.IntentKey.OTHERS_CLASSIFY_REQUEST_CODE && resultCode == RESULT_OK) {
            // 其它分类请求码
            String classifyName = data.getStringExtra("chooseClassify");
            if (!TextUtils.isEmpty(classifyName)) {
                txtClassify.setText(classifyName);
            } else {
                txtClassify.setText(getResources().getString(R.string.category_all_label));
            }
            secondClassifyCode = data.getStringExtra("chooseClassifyCode");
            if (!TextUtils.isEmpty(secondClassifyCode)) {
                goodsform.setMerchCategoryCode(secondClassifyCode);
            }
        } else if (requestCode == CommonConst.IntentKey.RED_WINE_REQUEST_CODE && resultCode == RESULT_OK) { // 葡萄酒产地
            String brandName = data.getStringExtra(CommonConst.IntentKey.RED_WINE_PLACE);
            if (!brandName.equals("null")) {
                txtRwPlace.setText(brandName);
            } else {
                txtRwPlace.setText(getResources().getString(R.string.category_all_label));
            }
            // 和传过来的值不相等，则添加
            if (!goodsform.getMerchPropertyValueCodeList().contains(data.getStringExtra(CommonConst.IntentKey.RED_WINE_CONSTANT))) {
                goodsform.getMerchPropertyValueCodeList().add(data.getStringExtra(CommonConst.IntentKey.RED_WINE_CONSTANT));
            }
        } else if (requestCode == CommonConst.IntentKey.FOREIGN_CLASSIFY_REQUEST_CODE && resultCode == RESULT_OK) { // 洋酒分类
            String brandName = data.getStringExtra(FOREIGN_CLASSIFY);
            if (!brandName.equals("null")) {
                txtFwClassify.setText(brandName);
            } else {
                txtFwClassify.setText(getResources().getString(R.string.category_all_label));
            }
            resolvePropertyCodeList(); // 设置选择的属性
        } else if (requestCode == CommonConst.IntentKey.FOREIGN_COUNTRY_REQUEST_CODE && resultCode == RESULT_OK) { // 洋酒国家
            String brandName = data.getStringExtra(FOREIGN_COUNTRY);
            if (!brandName.equals("null")) {
                txtFwCountry.setText(brandName);
            } else {
                txtFwCountry.setText(getResources().getString(R.string.category_all_label));
            }
            resolvePropertyCodeList(); // 设置选择的属性
        } else if (requestCode == CommonConst.IntentKey.BEER_CLASSIFY_REQUEST_CODE && resultCode == RESULT_OK) { // 啤酒分类
            String brandName = data.getStringExtra(BEER_CLASSIFY);
            if (!brandName.equals("null")) {
                txtClassify.setText(brandName);
            } else {
                txtClassify.setText(getResources().getString(R.string.category_all_label));
            }
            resolvePropertyCodeList(); // 设置选择的属性
        } else if (requestCode == CommonConst.IntentKey.BEER_COUNTRY_REQUEST_CODE && resultCode == RESULT_OK) { // 啤酒国家
            String brandName = data.getStringExtra(BEER_COUNTRY);
            if (!brandName.equals("null")) {
                txtBCountry.setText(brandName);
            } else {
                txtBCountry.setText(getResources().getString(R.string.category_all_label));
            }
            resolvePropertyCodeList(); // 设置选择的属性
        }
    }

    /**
     * 更新“分类”显示名称，并根据选择分类请求品牌列表数据
     *
     * @param data
     *         新增品类二级分类列表选择返回的数据
     */
    private void refreshViewAndData(Intent data) {
        String classifyName = data.getStringExtra("chooseClassify");  //获取所选二级分类名
        if (!TextUtils.isEmpty(classifyName)) {
            if (!classifyName.equals(txtClassify.getText().toString())) { // 分类改变，需清空上次所选品牌
                ACache aCache = ACache.get(getApplicationContext());
                aCache.remove(CommonConst.ACacheComstants.BRAND);
                txtBrandName.setText(getResources().getString(R.string.category_all_label));
            }
            secondClassifyCode = data.getStringExtra("chooseClassifyCode");
            txtClassify.setText(classifyName);  // 设置分类名
            getBrandWithSecCode(secondClassifyCode); // 获取品牌数据
        } else {
            txtClassify.setText(getResources().getString(R.string.category_all_label));
        }
        if (!TextUtils.isEmpty(secondClassifyCode)) {
            goodsform.setMerchCategoryCode(secondClassifyCode);
        }
    }

    /**
     * 通过商品的分类码，请求对应品牌数据列表对象
     * 粮油、饮料、副食、日化用品、五金、家电等新增品类具有二级分类码，传入则请求到对应品牌数据列表对象
     *
     * @param classifyCode
     *         分类码
     */
    private void getBrandWithSecCode(String classifyCode) {
        brandListRequest.setToken(agent.getToken()); // 设置token
        brandListRequest.setMerchCategoryCode(classifyCode); // 设置一级分类码
        agent.getApi().getTeaBrandList(brandListRequest).compose(OperatorUtils.<MerchCategoryListResponse>defaultSchedulers())
                .subscribe(new GeneralBusinessObserver<MerchCategoryListResponse>(CategoryFilterActivity.this, R.string.loading_common_msg) {
                    @Override
                    protected void onSuccess(MerchCategoryListResponse merchCategoryListResponse) {
                        String categoryCode = merchCategoryListResponse.getCategoryCode();  //一级分类码
                        if (categoryCode.equals(getResources().getString(R.string.category_wine_code))) {// 白酒
                            wineItem = serializeReturnModel(SpiritCategoryItem.class, merchCategoryListResponse);
                        } else if (categoryCode.equals(getResources().getString(R.string.category_red_wine_code))) { // 葡萄酒
                            redWineItem = serializeReturnModel(WineCategoryItem.class, merchCategoryListResponse);
                        } else if (categoryCode.equals(getResources().getString(R.string.category_tea_code))) { // 茶
                            Gson gson = new Gson();
                            Type type = new TypeToken<List<TeaCategoryItem>>() {
                            }.getType();
                            teaItem = gson.fromJson(gson.toJson(merchCategoryListResponse.getCategoryItem()), type);
                        } else if (categoryCode.equals(getResources().getString(R.string.category_foreign_wine_code))) { // 洋酒
                            foreignItem = serializeReturnModel(ForeignWineCategoryItem.class, merchCategoryListResponse);
                        } else if (categoryCode.equals(getResources().getString(R.string.category_beer_code))) { // 啤酒
                            Log.d("llq", "onSuccess: beeritem是空的");
                            beerItem = serializeReturnModel(BeerCategoryItem.class, merchCategoryListResponse);
                            if (beerItem == null) {
                                return;
                            }
                        } else if (categoryCode.equals("C01E01")) { //其它
                            othersItem = serializeReturnModel(OthersCategoryItem.class, merchCategoryListResponse);
                        } else if (categoryCode.equals(getString(R.string.category_code_drinks))) { //饮料
                            drinksItem = serializeReturnModel(DrinksCategoryItem.class, merchCategoryListResponse);
                        } else if (!categoryCode.equals(getString(R.string.category_code_drinks)) && categoryCode.contains(getString(R.string.category_code_drinks))) { //饮料二级分类码
                            drinksBrand = serializeReturnModel(DrinksCategoryItem.class, merchCategoryListResponse); // 饮料品牌
                        } else if (categoryCode.equals(getString(R.string.category_code_grain))) { // 粮油“C01G01”
                            grainItem = serializeReturnModel(GrainCategoryItem.class, merchCategoryListResponse);
                        } else if (!categoryCode.equals(getString(R.string.category_code_grain)) && categoryCode.contains(getString(R.string.category_code_grain))) { // 粮油二级分类码
                            grainBrand = serializeReturnModel(GrainCategoryItem.class, merchCategoryListResponse);  // 粮油品牌
                        } else if (categoryCode.equals(getString(R.string.category_code_non_staple))) { // 副食
                            nonStapleItem = serializeReturnModel(NonStapleCategoryItem.class, merchCategoryListResponse);
                        } else if (!categoryCode.equals(getString(R.string.category_code_non_staple)) && categoryCode.contains(getString(R.string.category_code_non_staple))) { // 副食二级分类码
                            nonStapleBrand = serializeReturnModel(NonStapleCategoryItem.class, merchCategoryListResponse); // 副食品牌
                        } else if (categoryCode.equals(getString(R.string.category_code_daily_used))) { // 日化用品
                            dailyUsedItem = serializeReturnModel(DailyUsedCategoryItem.class, merchCategoryListResponse);
                        } else if (!categoryCode.equals(getString(R.string.category_code_daily_used)) && categoryCode.contains(getString(R.string.category_code_daily_used))) { // 日化用品二级分类码
                            dailyUsedBrand = serializeReturnModel(DailyUsedCategoryItem.class, merchCategoryListResponse);  // 日化用品品牌
                        } else if (categoryCode.equals(getString(R.string.category_code_hardware))) { // 五金
                            hardwareItem = serializeReturnModel(HardwareCategoryItem.class, merchCategoryListResponse);
                        } else if (!categoryCode.equals(getString(R.string.category_code_hardware)) && categoryCode.contains(getString(R.string.category_code_hardware))) { // 五金二级分类码
                            hardwareBrand = serializeReturnModel(HardwareCategoryItem.class, merchCategoryListResponse);  // 五金品牌
                        } else if (categoryCode.equals(getString(R.string.category_code_electric))) { // 家电
                            electricItem = serializeReturnModel(ElectricCategoryItem.class, merchCategoryListResponse);
                        } else if (!categoryCode.equals(getString(R.string.category_code_electric)) && categoryCode.contains(getString(R.string.category_code_electric))) { //家电二级分类
                            electricBrand = serializeReturnModel(ElectricCategoryItem.class, merchCategoryListResponse); // 家电品牌
                        }
                    }

                    @Override
                    protected void onAlertTips(String displayMessage) {
                        ToastUtil.getInstance().show(TextUtils.isEmpty(displayMessage) ? "请求数据失败！" : displayMessage);
                    }
                });

    }

    private void initViews() {
        llytCancel = (LinearLayout) findViewById(R.id.llytCancel);
        llytOk = (LinearLayout) findViewById(R.id.llytOK);
        llytPrice = (LinearLayout) findViewById(R.id.llytPrice);
        llytBrand = (LinearLayout) findViewById(R.id.llytBrand);
        llytTeaSort = (LinearLayout) findViewById(R.id.llytTeaSort);
        llytTeaSeed = (LinearLayout) findViewById(R.id.llytTeaSeed);
        llytOdorType = (LinearLayout) findViewById(R.id.llytOdorType);
        llytRwPlace = (LinearLayout) findViewById(R.id.llytRWPlace);
        llytFwClassify = (LinearLayout) findViewById(R.id.llytFWClassify);
        llytFwCountry = (LinearLayout) findViewById(R.id.llytFWCountry);
        llytBClassify = (LinearLayout) findViewById(R.id.llytBClassify);
        llytBCountry = (LinearLayout) findViewById(R.id.llytBCountry);
        txtBrandName = (TextView) findViewById(R.id.txtBrandName);
        txtPrice = (TextView) findViewById(R.id.txtPrice);
        txtTeaSead = (TextView) findViewById(R.id.txtTeaSead);
        txtTeaSort = (TextView) findViewById(R.id.txtTeaSort);
        txtOdorType = (TextView) findViewById(R.id.txtOdorType);
        txtRwPlace = (TextView) findViewById(R.id.txtRWPlace);
        txtFwClassify = (TextView) findViewById(R.id.txtFWClassify);
        txtFwCountry = (TextView) findViewById(R.id.txtFWCountry);
        txtClassify = (TextView) findViewById(R.id.txtClassify);
        txtBCountry = (TextView) findViewById(R.id.txtBCountry);
        lineBrand = findViewById(R.id.lineBrand);
        lineTeaSead = findViewById(R.id.lineTeaSead);
        lineTeaSort = findViewById(R.id.lineTeaSort);
        lineOdorType = findViewById(R.id.lineOdorType);
        lineRwPlace = findViewById(R.id.lineRWPlace);
        lineFwClassify = findViewById(R.id.lineFWClassify);
        lineFwCountry = findViewById(R.id.lineFWCountry);
        lineClassify = findViewById(R.id.lineClassify);
        lineBCountry = findViewById(R.id.lineBCountry);
    }
}